<!--
form 重构相关准备
2.event 分离
使用maxins的方法通过覆盖覆盖已有action（如val等）来扩展相关方法

3.子表分离
4.父级数据关系与交互
主子表状态总结
form主子表的form向前获取owner->parentForm
action中异步获取model的form actuib 视列表行为parent data


找到onwer->owner的上级action-> 获取上级action数据actionData（当前主数据）
                          -> 无则使用当前triggerData.data(触发数据)作为parent


field type 的相关联动 减少control的固定形式
-->
<template>
    <div class="field-control" :class="{'field-control-error': !status.validate}">
        <Input ref="input" :disabled="disabled" :name="code" :type="inputType" @input="valueInput" :value="value">
        </Input>
        <div class="field-message" v-show="!status.validate">{{message}}</div>
    </div>
</template>

<script>
import $ from "@/common";
var messageText = {
  require: "${name}不能为空",
  format: "${type}格式不正确"
};
export default {
  subModuleStore: true,
  props: {
    code: {}
  },
  data() {
    return {
      inputType: "text",
      fristInput: true
    };
  },
  watch: {},
  computed: {
    status() {
      return (this.fields && this.fields[this.code]) || {};
    },
    message() {
      if (!this.status.validate) {
        return messageText[this.status.validateType]
          ? $.composeValue(
              messageText[this.status.validateType],
              this.status.model
            )
          : "请输出正确的值";
      }
    },
    value() {
      return this.data[this.code];
    },
    validate() {},
    ///控制判断
    valueNull() {
      return (
        this.value === null || this.value === undefined || this.value === ""
      );
    },
    disabled() {
      if (this.forceEnable !== null) {
        return !this.forceEnable;
      } else {
        return !this.status.enable;
      }
    },
    fieldModel() {
      return this.fields[this.code] && this.fields[this.code].model;
    }
  },
  methods: {
    doValidate() {
      var vaild = true;
      return vaild;
    },
    valueInput(v) {
      this.$emit("input", v);
      this.val(v);
      this.fristInput = false;
      //this.validate()
    },
    focus(v) {
      if (this.$refs.input && this.$refs.input.focus()) {
        this.$refs.input.focus();
      }
    },
    val(v, o) {
      if (o === undefined) {
        this.setValue({ code: this.code, value: v });
      } else {
        this.setValue({ code: v, value: o });
      }
    }
  },
  created() {}
};
</script>

<style lang="less">

</style>


